var RepairTimeInfo = function(repair){
  BaseModel.call(this);
  var self = this;

  var fn = {
    initData: function (repair) {
      self.month = repair.month;

      var data = repair.data;
      var repairData = [];
      var fields = RepairTimeInfo.dimensionsField;
      var maxHour = 0;
      var nameList = [];
      for (var i = 0; i < data.length; i++) {
        var obj = data[i];
        var name = obj.work_name;
        var repair = {
          name: name
        };
        nameList.push(name);
        for (var j = 0; j < fields.length; j++) {
          var field = fields[j];
          var value = obj[field];
          repair[field] = this.getHourTime(value);
        }

        var maxTime = repair.maxTime;
        if (maxHour < maxTime) {
          maxHour = maxTime;
        }

        repairData.push(repair);
      }
      self.repairData = repairData;
      self.maxHour = maxHour;
      self.nameList = nameList;
    },

    getHourTime: function (time) {
      if (SysUtil.isEmpty(time)) {
        return 0;
      }

      var hour = time / 3600;
      return _.round(hour, 2);
    }
  };

  this.getChartData = function () {
    var fields = RepairTimeInfo.dimensionsField;
    var repairData = this.repairData;
    var chartData = _.map(repairData, function (obj) {
      var data = [obj.name];
      for (var i = 0; i < fields.length; i++) {
        var field = fields[i];
        data.push(obj[field]);
      }
      return data;
    });
    return chartData;
  };

  fn.initData(repair);
};

RepairTimeInfo.dimensionsField = ['avgTime', 'minTime', 'maxTime'];
